<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
class TypeController extends CommonController {
 
  //===================================产品订单
    public function index() {
            //维修大分类
            $cat=M('type_cate');
            $catlist=$cat->select();
            $this->assign('catlist',$catlist);
            
            //维修分类列表
    	    $M = M('type');
    	    $count = $M->count();
    		$page =new \Think\Page($count,10);
    		$showPage = $page->show();
    		$this->assign("page", $showPage);
    		$this->assign("pageCount",$count);
    		$this->assign("list", M('type')->limit($page->firstRow, $page->listRows)->select());


    	    $this->display();
    }


    public function addlist(){
        $lis=M('type_cate');
        $list=$lis->where('p_id=0')->select();

            if(IS_POST){
                $data=array();

                $data['p_id']=I('post.cat_id');
                $data['title']=I('post.title');
                $data['intro']=I('post.intro');

                if(M('type_cate')->add($data)){
                    $this->success('添加副分类成功',U('Type/index'));
                    exit();
                }else{

                    $this->success('添加副分类失败',U('Type/index'));
                    exit();
                }
            }

            $this->assign('list',$list);
            $this->display();


    }




    //添加主分类

    public function addfirst(){
        if(IS_POST){
               $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   =     3145728 ;// 设置附件上传大小
                $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
                $upload->savePath  =     ''; // 设置附件上传（子）目录
                // 上传文件
                $info   =   $upload->upload();
                if(!$info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                }else{// 上传成功
                    $data["pic"]=$info["pic"]["savepath"].$info["pic"]["savename"];
                }

                $data['create_time'] = time();
                $data['cat_name']=I('cat_name');
            if(M('type_cate')->add($data)){

                $this->success('添加主分类成功',U('Type/index'));
                exit();
                }else{

                $this->success('添加副分类成功',U('Type/index'));
                exit();
            }
         
        }

        $this->display();
    }




    public function add(){
            $cat=M('type_cate');
            $c=$cat->select();    
            $catlist=getCatTree($c);
            $this->assign('catlist',$catlist);

        
            if(IS_POST){
                $data=array();
                $data=I('post.');
                $data['addtime']=time();
                if(M('type')->add($data)){
                    $this->success('添加分类成功',U('Type/index'));
                    exit();
                }else{

                    $this->success('添加分类失败',U('Type/index'));
                    exit();
                }
            }

            $this->display();
    }



      
   
    
}

?>